home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / RTrace-1.0-src / config.h < prev    next >
Text File  |  1992-09-18  |  10KB  |  482 lines

  1. /*
  2.  * Copyright (c) 1988, 1992 Antonio Costa, INESC-Norte.
  3.  * All rights reserved.
  4.  *
  5.  * This code received contributions from the following people:
  6.  *
  7.  *  Roman Kuchkuda      - basic ray tracer
  8.  *  Mark VandeWettering - MTV ray tracer
  9.  *  Augusto Sousa       - overall, shading model
  10.  *
  11.  * Redistribution and use in source and binary forms are permitted
  12.  * provided that the above copyright notice and this paragraph are
  13.  * duplicated in all such forms and that any documentation,
  14.  * advertising materials, and other materials related to such
  15.  * distribution and use acknowledge that the software was developed
  16.  * by Antonio Costa, at INESC-Norte. The name of the author and
  17.  * INESC-Norte may not be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  */
  23.  
  24. /**********************************************************************
  25.  *    RAY TRACING - Configuration - Version 7.3.2                     *
  26.  *                                                                    *
  27.  *    MADE BY    : Antonio Costa, INESC-Norte, October 1988           *
  28.  *    ADAPTED BY : Antonio Costa, INESC-Norte, June 1989              *
  29.  *    MODIFIED BY: Antonio Costa, INESC-Norte, August 1992            *
  30.  **********************************************************************/
  31.  
  32. #define PROGRAM_VERSION "7.3.2"
  33.  
  34. #include <stdio.h>
  35. #include <math.h>
  36.  
  37. /***** Constants *****/
  38. #ifndef NULL
  39. #define NULL (0)
  40. #endif
  41. #ifdef TRUE
  42. #undef TRUE
  43. #endif
  44. #define TRUE (1)
  45. #ifdef FALSE
  46. #undef FALSE
  47. #endif
  48. #define FALSE (0)
  49. #ifndef MAXINT
  50. #define MAXINT (~(1 << (sizeof(int) * 8 - 1)))
  51. #endif
  52.  
  53. /***** Types *****/
  54. typedef
  55. int             boolean;
  56.  
  57. typedef
  58. double          real;
  59.  
  60. typedef
  61. char           *char_ptr;
  62.  
  63. typedef
  64. FILE           *file_ptr;
  65.  
  66. /***** Boolean operators *****/
  67. #define NOT !
  68. #define AND &&
  69. #define OR  ||
  70.  
  71. #define BIT_NOT ~
  72. #define BIT_AND &
  73. #define BIT_OR  |
  74. #define BIT_XOR ^
  75.  
  76. /***** Integer operators *****/
  77. #define DIV /
  78. #define MOD %
  79.  
  80. #define SHL <<
  81. #define SHR >>
  82.  
  83. /***** Others *****/
  84. #define PREINC(x) (++(x))
  85. #define POSINC(x) ((x)++)
  86. #define PREDEC(x) (--(x))
  87. #define POSDEC(x) ((x)--)
  88.  
  89. #define SUCC(x) ((x) + 1)
  90. #define PRED(x) ((x) - 1)
  91. #define ODD(x)  ((x) & 1)
  92.  
  93. #define TRUNC(x) ((long int) floor((double) (x)))
  94. #define ROUND(x) ((long int) floor((double) (x) + 0.5))
  95.  
  96. #define ABS(x)      ((real) fabs((double) (x)))
  97. #define FRAC(x)     ((real) ((double) (x) - floor((double) (x))))
  98. #define SIN(x)      ((real) sin((double) (x)))
  99. #define COS(x)      ((real) cos((double) (x)))
  100. #define SQR(x)      ((real) ((double) (x) * (double) (x)))
  101. #define SQRT(x)     ((real) sqrt((double) (x)))
  102. #define POWER(x, y) ((real) pow((double) (x), (double) (y)))
  103. #define ARCCOS(x)   ((real) acos((double) (x)))
  104.  
  105. #define EXIT exit(0)
  106.  
  107. #ifdef THINK_C
  108.  
  109. #define PROTOTYPES
  110.  
  111. /* On the mac, we trap HALT to put up an error dialog and continue */
  112.  
  113. #define HALT mac_halt()
  114.  
  115. /* On the mac, this macro gives background tasks a little time */
  116.  
  117. #define PROCESS_MAC_EVENT    if (get_another_event) process_mac_event();
  118.  
  119. #else
  120.  
  121. #define HALT exit(1)
  122.  
  123. #define PROCESS_MAC_EVENT
  124.  
  125. #endif
  126.  
  127. /***** Compiler stuffs *****/
  128. #ifdef THINK_C
  129. #include <string.h>
  130. #include <stdlib.h>
  131. #include <console.h>
  132. #ifndef TIME
  133. #define TIME
  134. #endif
  135. #ifdef TIMES
  136. #undef TIMES
  137. #endif
  138. #define RANDOM_START srand(1)
  139. #define RANDOM       ((real) rand() / 32767.0 )
  140. #else
  141.  
  142. #ifdef vms
  143. #include <string.h>
  144. #include <stdlib.h>
  145. #ifdef TIME
  146. #undef TIME
  147. #endif
  148. #ifndef TIMES
  149. #define TIMES
  150. #endif
  151. #define RANDOM_START srand(1)
  152. #ifdef RAND_MAX
  153. #define RANDOM       ((real) rand() / RAND_MAX)
  154. #else
  155. #define RANDOM       ((real) rand() / (real) MAXINT)
  156. #endif
  157. #else
  158.  
  159. #ifdef _transputer
  160. #include <stdlib.h>
  161. #include <string.h>
  162. #ifdef TIMES
  163. #undef TIMES
  164. #endif
  165. #ifndef TIME
  166. #define TIME
  167. #endif
  168. #define RANDOM_START srand(1)
  169. #ifdef RAND_MAX
  170. #define RANDOM       ((real) rand() / RAND_MAX)
  171. #else
  172. #define RANDOM       ((real) rand() / 32767.0)
  173. #endif
  174. #undef __DATE__
  175. #undef __TIME__
  176. #define ECHO
  177. #else
  178.  
  179. #ifdef dos
  180. #include <stdlib.h>
  181. #include <string.h>
  182. #ifdef __TURBOC__
  183. #include <alloc.h>
  184. #include <dos.h>
  185. #endif
  186. #ifdef TIMES
  187. #undef TIMES
  188. #endif
  189. #ifndef TIME
  190. #define TIME
  191. #endif
  192. #ifdef __TURBOC__
  193. #ifdef MAIN_MODULE
  194. extern unsigned int _stklen = 65000U;
  195. #endif
  196. #endif
  197. #define RANDOM_START srand(1)
  198. #ifdef RAND_MAX
  199. #define RANDOM       ((real) rand() / RAND_MAX)
  200. #else
  201. #define RANDOM       ((real) rand() / (real) MAXINT)
  202. #endif
  203. #define ECHO
  204. #else
  205.  
  206. #ifdef hpux
  207. #include <memory.h>
  208. #ifdef TIME
  209. #undef TIME
  210. #endif
  211. #ifndef TIMES
  212. #define TIMES
  213. #endif
  214. #define RANDOM_START srand(1)
  215. #ifdef RAND_MAX
  216. #define RANDOM       ((real) rand() / RAND_MAX)
  217. #else
  218. #define RANDOM       ((real) rand() / 32767.0)
  219. #endif
  220. #else
  221.  
  222. #include <memory.h>
  223. #include <stdlib.h>
  224. #ifdef TIME
  225. #undef TIME
  226. #endif
  227. #ifndef TIMES
  228. #define TIMES
  229. #endif
  230. #define RANDOM_START srand48(1)
  231. #define RANDOM       ((real) drand48() )
  232. #endif
  233. #endif
  234. #endif
  235. #endif
  236. #endif        /* ...for THINK_C */
  237.  
  238. #ifndef __DATE__
  239. #define __DATE__ "Aug 11 1992"
  240. #endif
  241. #ifndef __TIME__
  242. #define __TIME__ "00:30:00"
  243. #endif
  244.  
  245. /***** If there is no void type, define NOVOID *****/
  246. #ifdef NOVOID
  247. #define void char
  248. #define void_ptr char_ptr
  249. #else
  250. typedef
  251. void           *void_ptr;
  252. #endif
  253.  
  254. /***** If there are no register variables, define NOREGISTERS *****/
  255. #ifdef NOREGISTERS
  256. #define REG
  257. #undef NOREGISTERS
  258. #else
  259. #define REG register
  260. #endif
  261.  
  262. /***** If there are function prototypes, define PROTOTYPES *****/
  263. #ifndef PROTOTYPES
  264. #if __STDC__
  265. #ifndef NOVOID
  266. #define PROTOTYPES
  267. #endif
  268. #endif
  269. #endif
  270.  
  271. #ifdef NOVOID
  272. #undef NOVOID
  273. #endif
  274.  
  275. /***** If there is a function that gives time, define TIME or TIMES *****/
  276. #ifndef TIME
  277. #ifndef TIMES
  278. #define CPU_CLOCK ((real) 0)
  279. #endif
  280. #endif
  281. /* Using time() function */
  282. #ifdef TIME
  283. #include <time.h>
  284. /* CPU_CLOCK must return time in milliseconds */
  285. #define CPU_CLOCK ((real) ((double) time(0) * 1000.0))
  286. #undef TIME
  287. #endif
  288. /* Using times() function */
  289. #ifdef TIMES
  290. #ifdef vms                      /* VAX-VMS */
  291. #include <time.h>
  292. #define tms_utime proc_user_time
  293. #define tms_stime proc_system_time
  294. #define tms tbuffer_t
  295. #else
  296. #include <sys/types.h>
  297. #include <sys/times.h>
  298. #ifndef CLK_TCK
  299. #ifdef ultrix                   /* ULTRIX */
  300. #define CLK_TCK (60)
  301. #else                           /* Others */
  302. #define CLK_TCK (60)
  303. #endif
  304. #endif
  305. #endif
  306. /* CPU_CLOCK must return time in milliseconds */
  307. #define CPU_CLOCK cpu_clock()
  308. static real
  309. cpu_clock()
  310. {
  311. #ifdef vms
  312.   tms             cpu_time;
  313. #else
  314.   struct tms      cpu_time;
  315. #endif
  316.   (void) times(&cpu_time);
  317.   return (real) ((double) cpu_time.tms_utime * 1000.0 / (double) CLK_TCK);
  318. }
  319. #undef TIMES
  320. #endif
  321.  
  322. /***** If cannot assign structs to structs, define NOSTRUCTASSIGN *****/
  323. #ifdef NOSTRUCTASSIGN
  324. #define STRUCT_ASSIGN(d, s)\
  325. (void) memcpy((char_ptr) &(d), (char_ptr) &(s), sizeof(d))
  326. #undef NOSTRUCTASSIGN
  327. #else
  328. #define STRUCT_ASSIGN(d, s) (d) = (s)
  329. #endif
  330.  
  331. #define ARRAY_ASSIGN(d, s, c)\
  332. (void) memcpy((char_ptr) (d), (char_ptr) (s), (c) * sizeof(d))
  333.  
  334. /***** Input & Output *****/
  335. #define IO_EOF   (-1)
  336. #define IO_OK    (0)
  337. #define IO_OPEN  (1)
  338. #define IO_READ  (2)
  339. #define IO_WRITE (3)
  340. #define IO_SEEK  (4)
  341.  
  342. #define EOT     '\0'
  343. #define NEWLINE '\n'
  344. #define SPACE   ' '
  345. #define TAB     '\t'
  346.  
  347. #define INPUT  stdin
  348. #define OUTPUT stdout
  349. #define ERROR  stderr
  350.  
  351. #define READ_BINARY  "r+b"
  352. #define READ_TEXT    "r+t"
  353. #define WRITE_BINARY "w+b"
  354. #define WRITE_TEXT   "w+t"
  355.  
  356. #ifndef SEEK_SET
  357. #define SEEK_SET 0
  358. #endif
  359.  
  360. static int      IO_status;
  361.  
  362. #define STATUS(file, code)\
  363. IO_status = feof(file) ? IO_EOF : (ferror(file) ? code : IO_OK)
  364.  
  365.  
  366. #ifdef THINK_C
  367.  
  368.     /* on the mac, we need to check when we're opening a temp file,
  369.         and make sure we create it in the RTrace directory */
  370.  
  371. #define OPEN(file, name, mode)\
  372. do {\
  373.     if ((((char *) name)[0] == '~') && (((char *) name)[1] == '~'))\
  374.         SetVol( (StringPtr) NULL, temp_folder_wd_id);\
  375.     else\
  376.         SetVol( (StringPtr) NULL, sff_file_wd_id);\
  377.     (file) = fopen(name, mode);\
  378.     IO_status = (file) ? IO_OK : IO_OPEN;\
  379. } while (0)
  380.  
  381. #else
  382.  
  383. #define OPEN(file, name, mode)\
  384. do {
  385.   (file) = fopen(name, mode);\
  386.   IO_status = (file) ? IO_OK : IO_OPEN;\
  387. } while (0)
  388.  
  389. #endif
  390.  
  391.  
  392. #define CLOSE(file)\
  393. IO_status = fclose(file) ? IO_EOF : IO_OK
  394.  
  395. #define FLUSH(file)\
  396. IO_status = fflush(file) ? IO_EOF : IO_OK
  397.  
  398. #ifdef THINK_C
  399.  
  400. /* When running on the mac, we need to send the output lines to the log.  */
  401. extern void    mac_write(FILE *file, char *format, ...);
  402.  
  403. #define WRITE    (void) mac_write
  404.  
  405. #else
  406.  
  407. #define WRITE (void) fprintf
  408.  
  409. #endif
  410.  
  411. #define WRITE_CHAR(file, c)\
  412. do {\
  413.   PROCESS_MAC_EVENT    \
  414.   (void) putc(c, file);\
  415.   STATUS(file, IO_WRITE);\
  416. } while (0)
  417.  
  418. static int
  419. PEEK_CHAR(file)
  420.   file_ptr        file;
  421. {
  422.   int             character;
  423.  
  424.   character = getc(file);
  425.   STATUS(file, IO_READ);
  426.   if (IO_status == IO_OK)
  427.     return ungetc(character, file);
  428.   return IO_EOF;
  429. }
  430.  
  431. #define END_OF_LINE(file)\
  432. (PEEK_CHAR(file) == NEWLINE)
  433.  
  434. #define READ_LINE(file)\
  435. {\
  436.   PROCESS_MAC_EVENT \
  437.   while ((getc(file) != NEWLINE) AND((STATUS(file, IO_READ)) == IO_OK));\
  438.   }\
  439.  
  440. #define READ_CHAR(file, character)\
  441. do {\
  442.   PROCESS_MAC_EVENT \
  443.   (character) = (unsigned char) getc(file);\
  444.   STATUS(file, IO_READ);\
  445. } while (0)
  446.  
  447. #define READ_REAL(file, real)\
  448. do {\
  449.     PROCESS_MAC_EVENT \
  450.     IO_status = fscanf(file, "%lf", real) ? IO_OK : IO_READ; \
  451.     }\
  452. while (0)
  453.  
  454. #define READ_STRING(file, string)\
  455. { PROCESS_MAC_EVENT    IO_status = fscanf(file, "%s", string) ? IO_OK : IO_READ; }
  456.  
  457. #define SEEK(file, offset)\
  458. do { PROCESS_MAC_EVENT    IO_status = fseek(file, offset, SEEK_SET) ? IO_SEEK : IO_OK; }\
  459. while (0)
  460.  
  461. /***** Memory allocation *****/
  462.  
  463. #ifdef THINK_C
  464.  
  465. /* on the mac, we make a list of all allocations so we can easily free
  466.     them later */
  467.  
  468. #define ALLOC(p, s, c)\
  469. (p) = (s *) mac_alloc((unsigned int) ((c) * sizeof(s)))
  470.  
  471. #define FREE(p) mac_free((char_ptr) (p))
  472.  
  473.  
  474. #else
  475.  
  476. #define ALLOC(p, s, c)\
  477. (p) = (s *) malloc((unsigned int) ((c) * sizeof(s)))
  478.  
  479. #define FREE(p) free((char_ptr) (p))
  480.  
  481. #endif
  482.